
import { getById } from "../../utils/db.js"
import config from "../../utils/config"
Page({
  data:{
    //音频地址
    src:'',
    //图片
    poster:'',
    appName:config.appName
  },
  async onLoad(e){
    wx.showLoading({title:"正在加载"})
    let {bookId,audioId}=e;   //获取id

    //读取book内容
   var result =await  getById({collection:"book",id:bookId}).catch(err=>{
      console.error(err)
    })
    var poster=result.data.fileids[0];    //图书封面图片

    //读取audio内容
    var result = await getById({collection:"audio",id:audioId}).catch(err=>{
      console.error(err)
    })
  
    let {audioPath:src,audioName}=result.data;
    var arr=audioName.split(".")
    arr.pop()

    this.setData({
      poster,
      src,
      name:arr.join("")
    })
    wx.hideLoading()
  },
})